package com.trainer.Attributes;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Formatter;

public class Weight extends ExAttribute{

	double mWeight;
	Unit mUnit;
	
	public static enum Unit {
		KILOGRAMS, POUNDS 
	}
	
	
	public Weight(double weight, Unit unit)
	{
		mWeight = weight;
		mUnit = unit;
	}
	
	public double GetWeight()
	{
		return mWeight;
	}
	
	public void SetWeight(double weight)
	{
		mWeight = weight;
	}
	
	public Unit GetUnit()
	{
		return mUnit;
	}
	
	public void SetUnit(Unit unit)
	{
		mUnit = unit;
	}
	
	public String GetUnitString()
	{
		switch(mUnit)
		{
		case KILOGRAMS:
			return "Kg";
		case POUNDS:
			return "lbs";
		default:
			return "NA";
		}
	}
	
	public void ConvertTo(Unit unit)
	{
		switch(unit)
		{
		case KILOGRAMS:
			ConvertToKg();
			mUnit = unit;
			return;
		case POUNDS:
			ConvertToLb();
			mUnit = unit;
			return;
		default:
			return;
		}
	}
	
	private void ConvertToKg()
	{
		switch(mUnit)
		{
		case KILOGRAMS:
			return;
		case POUNDS:
			mWeight *= .45359237;
			return;
		}
	}
	
	private void ConvertToLb()
	{
		switch(mUnit)
		{
		case KILOGRAMS:
			mWeight *= 2.20462262;
			return;
		case POUNDS:
			return;
		}
	}
	
	public String Display()
	{
		NumberFormat format = new DecimalFormat("#.00"); 
		return "Weight: " + format.format(GetWeight()) +' '+ GetUnitString();
	}
	
}
